using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ToolsLayer;
using Webcar.BLL;
namespace Webcar.Controls.View
{
    public partial class CarMoveView : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GridViewStyler gvs = new GridViewStyler(this.GridView1);
            gvs.SetStyle();
        }

        public void InitView(string dept, string start_date, string end_date)
        {
            string sql = "";
            if (dept == "all")
            {
                sql = @"select 0 xh,d.car_note,a.operator,convert(varchar(10),a.move_date,120) as move_date,cause
                        ,b.dept_name as old_dept_name,c.dept_name as new_dept_name,d.record_no
                         from bs_car_move a,dept b,dept c,v_bs_car_record d
                        where a.old_dept = b.dept_code and a.new_dept = c.dept_code
                        and a.car_no = d.car_no and convert(varchar(10),a.move_date,120) between '{0}' and '{1}'";
                sql = string.Format(sql, start_date, end_date);
            }
            else
            {
                sql = @"select 0 xh,d.car_note,a.operator,convert(varchar(10),a.move_date,120) as move_date,cause
                        ,b.dept_name as old_dept_name,c.dept_name as new_dept_name,d.record_no
                         from bs_car_move a,dept b,dept c,v_bs_car_record d
                        where a.old_dept = b.dept_code and a.new_dept = c.dept_code
                        and a.car_no = d.car_no and convert(varchar(10),a.move_date,120) between '{1}' and '{2}'
                        and (a.old_dept=@v_dept or a.new_dept='{0}')";
                sql = string.Format(sql, dept, start_date, end_date);
            }
            DataSet ds = ToolsLayer.DB.ExecuteDataset(sql);
            int i=0;
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                row["xh"] = ++i;
            }
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }
    }
}